package com.example.a79273.shandianban.view;

import android.content.Context;
import android.content.res.ColorStateList;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.widget.TextView;

import com.example.a79273.shandianban.R;

/**
 * Created by lenovo on 2016/8/31.
 */
public class MyTextView extends TextView {
    private int mWidth,mHeight;
    private Paint mPaint = new Paint();
    private int currentSize = 2;
    public MyTextView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    public MyTextView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public MyTextView(Context context) {
        super(context);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        if(mPaint == null) {
            mPaint = new Paint();
        }
        final int paddingRight = getPaddingRight();
        final int paddingTop = getPaddingTop();
        final int paddingLeft = getPaddingLeft();
        final int paddingBottom = getPaddingBottom();
        //获取控件的宽和高
        mWidth = getWidth();
        mHeight = getHeight();
        mPaint.setColor(R.color.colorProductInfoTabtext);
        mPaint.setStrokeWidth((float) currentSize);
        // 在中间画一条线 考虑边距
        canvas.drawLine(paddingLeft,mHeight/2,mWidth-paddingRight,mHeight/2,mPaint);
    }
}
